import { initialState } from "../constants/constants"

//创建reducer函数math
const reducerMath = (state = initialState, action) => {
  switch (action.type) {
    case 'ADD_ONE':
      return {
        num: state.num + action.num,
        des: '基于React与Redux实现的计数器'
      }
    case 'ACTION_PINGFANG':
      return Object.assign({}, state, { num: state.num * state.num })   //对象拷贝并作部分修改
    case 'SET_LING':
      return { ...state, num: action.num }       //对象拷贝并作部分修改
    case 'GET_CODE':
      return { ...state, num: action.newnum }
    default:
      return state
  }
}

export default reducerMath;
